package com.cup.bddm.util;

import java.util.Date;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import com.cup.bddm.impala.po.User;

public class CacheUtil {
	// token的有效期1小时
	public static final long token_pass_time = 3600000;
	// token的时间 token=time
	public static ConcurrentMap<String, Date> times = new ConcurrentHashMap<>();
	// 已登录的用户 token=user
	public static ConcurrentMap<String, User> users = new ConcurrentHashMap<>();

	public static String getToken(User user) {
		String token = uuid();
		times.put(token, new Date());
		users.put(token, user);
		return token;
	}

	public static void delayToken(String token) {
		times.put(token, new Date());
	}

	public static void delToken(String token) {
		times.remove(token);
		users.remove(token);
	}

	private static String uuid() {
		return UUID.randomUUID().toString().replaceAll("-", "");
	}

}
